home *** CD-ROM | disk | FTP | other *** search
- #
- # string.test
- #
- # Tests for the cindex, clength, crange, replicate, csubstr, and translit
- # commands.
- #---------------------------------------------------------------------------
- # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: string.test,v 3.0 1993/11/19 06:58:05 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- # Test the 'cindex' command.
-
- Test string-1.1 {cindex tests} {
- cindex ABCDEFG 1
- } 0 {B}
-
- Test string-1.2 {cindex tests} {
- cindex ABCDEFG 3+1
- } 0 {E}
-
- Test string-1.3 {cindex tests} {
- cindex ABCDEFG 3*2
- } 0 {G}
-
- Test string-1.4 {cindex tests} {
- cindex ABCDEFG 7
- } 0 {}
-
- Test string-1.5 {cindex tests} {
- cindex ABCDEFG end-2
- } 0 {E}
-
- Test string-1.6 {cindex tests} {
- cindex ABCDEFG len-3
- } 0 {E}
-
- Test string-1.7 {cindex tests} {
- cindex ABCDEFG lenx-3
- } 1 {syntax error in expression "7x-3"}
-
- Test string-1.8 {cindex tests} {
- cindex ABCDEFG
- } 1 {wrong # args: cindex string indexExpr}
-
- Test string-1.9 {cindex tests} {
- cindex ABCDEFG 1 10
- } 1 {wrong # args: cindex string indexExpr}
-
- # Test the 'clength' command.
-
- Test string-2.1 {clength tests} {
- clength ABCDEFG
- } 0 {7}
-
- Test string-2.2 {clength tests} {
- clength "ABCD XYZ"
- } 0 {8}
-
- Test string-2.3 {clength tests} {
- clength
- } 1 {wrong # args: clength string}
-
- # Test the crange command.
-
- Test string-3.1 {crange tests} {
- crange ABCDEFG 1 3
- } 0 {BCD}
-
- Test string-3.2 {crange tests} {
- crange ABCDEFG 2 end
- } 0 {CDEFG}
-
- Test string-3.3 {crange tests} {
- set foo [replicate ABCD 500]
- crange $foo 25*4 500-1
- } 0 [replicate ABCD 100]
-
- Test string-3.4 {crange tests} {
- crange
- } 1 {wrong # args: crange string firstExpr lastExpr}
-
- Test string-3.5 {crange tests} {
- crange ABCD 4 1
- } 0 {}
-
- Test string-3.6 {crange tests} {
- crange ABCD end-2 len-1
- } 0 {BCD}
-
- Test string-3.7 {crange tests} {
- crange ABCD len-3 end-1
- } 0 {BC}
-
- Test string-3.8 {crange tests} {
- crange ABCD lenx-3 end-1
- } 1 {syntax error in expression "4x-3"}
-
- # Test the 'replicate' command
-
- Test string-4.1 {replicate tests} {
- replicate AbCd 4
- } 0 {AbCdAbCdAbCdAbCd}
-
- Test string-4.2 {replicate tests} {
- replicate X 1000
- } 0 "[replicate X 250][replicate X 250][replicate X 250][replicate X 250]"
-
- Test string-4.3 {replicate tests} {
- replicate X
- } 1 {wrong # args: replicate string countExpr}
-
- # Test the csubstr command.
-
- Test string-5.1 {csubstr tests} {
- csubstr ABCDEFG 1 2+1
- } 0 {BCD}
-
- Test string-5.2 {csubstr tests} {
- csubstr ABCDEFG 1+1 end
- } 0 {CDEFG}
-
- Test string-5.3 {csubstr tests} {
- set foo [replicate ABCD 500]
- csubstr $foo 25*4 100*4
- } 0 [replicate ABCD 100]
-
- Test string-5.4 {csubstr tests} {
- csubstr
- } 1 {wrong # args: csubstr string firstExpr lengthExpr}
-
- Test string-5.5 {csubstr tests} {
- csubstr ABCD 4 1
- } 0 {}
-
- Test string-5.6 {csubstr tests} {
- csubstr ABCD 1 end-1
- } 0 {BC}
-
- Test string-5.7 {csubstr tests} {
- csubstr ABCD len-2 end
- } 0 {CD}
-
- Test string-5.8 {csubstr tests} {
- csubstr ABCD 0 len
- } 0 {ABCD}
-
- # Test the translit command.
-
- Test string-6.1 {translit tests} {
- set str "Captain Midnight Secret Decoder Ring"
- translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str
- } 0 {Pncgnva Zvqavtug Frperg Qrpbqre Evat}
-
- Test string-6.2 {translit tests} {
- set str "Captain Midnight Secret Decoder Ring"
- set str2 [translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str]
- translit {A-MN-Za-mn-z} {N-ZA-Mn-za-m} $str2
- } 0 {Captain Midnight Secret Decoder Ring}
-
- Test string-6.3 {translit tests} {
- translit
- } 1 {wrong # args: translit from to string}
-
- # Test the ctoken command
-
- Test string-7.1 {ctoken tests} {
- ctoken
- } 1 {wrong # args: ctoken strvar separators}
-
- Test string-7.2 {ctoken tests} {
- ctoken a b c
- } 1 {wrong # args: ctoken strvar separators}
-
- Test string-7.3 {ctoken tests} {
- set orgstr " \t this\tis \n a test "
- set s1 [ctoken orgstr " \t\n"]
- set s1v $orgstr
- set s2 [ctoken orgstr " \t\n"]
- set s2v $orgstr
- set s3 [ctoken orgstr " \t\n"]
- set s3v $orgstr
- set s4 [ctoken orgstr " \t\n"]
- set s4v $orgstr
- set s5 [ctoken orgstr " \t\n"]
- set s5v $orgstr
- list $s1 $s1v $s2 $s2v $s3 $s3v $s4 $s4v $s5 $s5v
- } 0 [list "this" "\tis \n a test " \
- "is" " \n a test " \
- "a" " test " \
- "test" " " \
- "" ""]
-
- Test string-8.1 {cexpand tests} {
- cexpand
- } 1 {wrong # args: cexpand string}
-
- Test string-8.2 {cexpand tests} {
- cexpand x y
- } 1 {wrong # args: cexpand string}
-
- Test string-8.3 {cexpand tests} {
- cexpand {\n\n\t}
- } 0 "\n\n\t"
-
- Test string-8.4 {cexpand tests} {
- cexpand {xxxxxxx\nx\nxxx\ta}
- } 0 "xxxxxxx\nx\nxxx\ta"
-
- Test string-8.5 {cexpand tests} {
- cexpand "[replicate a 100]$\\n\\t$\\\[[replicate b 100]"
- } 0 "[replicate a 100]$\n\t$\[[replicate b 100]"
-
- Test string-9.1 {cequal tests} {
- cequal
- } 1 {wrong # args: cequal string1 string2}
-
- Test string-9.2 {cequal tests} {
- cequal a b c
- } 1 {wrong # args: cequal string1 string2}
-
- Test string-9.3 {cequal tests} {
- cequal ab c
- } 0 0
-
- Test string-9.3 {cequal tests} {
- cequal abcded abcded
- } 0 1
-
-
-